package com.wss.common.context.util;


import com.wss.common.context.exception.LoadConfigRuntimeException;
import org.apache.log4j.Logger;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 系统文件配置
 */
public abstract class SystemConfig {

	private static final Logger logger = Logger.getLogger(SystemConfig.class);  //日志文件配置
	private static final String CONFIG_FILE = "system.properties";

	//----------------------基本配置
	private static String DOMAIN_NAME;
	private static String PROJECT_NAME;

	//----------------------三方平台相关
	private static String COMPONENT_TOKEN;
	private static String COMPONENT_APP_SECRET;
	private static String COMPONENT_APP_ID;
	private static String ENCODING_AES_KEY;
	//全网发布相关
	public static final String  TEST_APP_ID = "wx570bc396a51b8ff8";
	public static final String  TEST_GH_ID = "gh_3c884a361561";


	static {
		InputStream inputStream = null;
		try {
			logger.info("加载api及版本等系统主要配置");
			ClassPathResource resource = new ClassPathResource(CONFIG_FILE);
			inputStream = resource.getInputStream();
			Properties properties = new Properties();
			properties.load(inputStream);

			DOMAIN_NAME = properties.getProperty("sys.domainName");
			PROJECT_NAME = properties.getProperty("sys.projectName");

			COMPONENT_TOKEN = properties.getProperty("component.token");
			COMPONENT_APP_SECRET = properties.getProperty("component.appSecret");
			COMPONENT_APP_ID = properties.getProperty("component.appId");
			ENCODING_AES_KEY = properties.getProperty("component.encodingAesKey");
			logger.info("加载api及版本等系统主要配置 成功！！");
		} catch (Exception e) {
			logger.info("加载api及版本等系统主要配置报错", e);
			throw new LoadConfigRuntimeException("加载" + CONFIG_FILE + " 配置文件信息报错", e);
		}finally {
			if(inputStream!=null){
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public static String getComponentToken() {
		return COMPONENT_TOKEN;
	}

	public static String getComponentAppSecret() {
		return COMPONENT_APP_SECRET;
	}

	public static String getComponentAppId() {
		return COMPONENT_APP_ID;
	}

	public static String getEncodingAesKey() {
		return ENCODING_AES_KEY;
	}

	public static boolean isDebug(){
		return true;
	}

	public static String getDomainName() {
		return DOMAIN_NAME;
	}

	public static String getProjectName() {
		return PROJECT_NAME;
	}
}
